<?php
	namespace Admin\Controller;
	use Think\Controller;
	use User\Api\UserApi;

	class PublicController extends Controller{
		public function login($username=null ,$password=null ,$verify=null){

		 if(IS_POST){
            /* 检测验证码 TODO: */
            if(check_verify($verify)){
				/* 调用UC登录接口登录 */
			
				$User=new UserApi;

				$Uid=$User->login($username,$password);

				if($Uid > 0){
					 //$this->success('登录成功！', U('Index/index'));
					//登录用户
					$Member=D('Member');
					
					//$bo=$Member->login($Uid);
					
					if($Member->login($Uid)){
						 $this->success('登录成功！', U('Index/index'));

					}else{
						$this->error($Member->getError());
					}
				}
				else{
					switch($Uid){
						case -1: $error= '用户不存在或被禁用！';break;
						case -2: $error= '密码错误！';break;
						default: $error= '未知错误！';break;
					}
					$this->error($error);
				}
 
            }else{
				$this->error('验证码输入错误！');
			}
		}else{
				$this->display();
			}
		}
		public function logout(){
			if(is_login()){
				D('Member')->logout();
				session('[destroy]');// 销毁session
				$this->success('退出成功！', U('login'));

			}else {
				$this->redirect('login');
			}
		}
		 public function verify(){
			$verify = new \Think\Verify();
			$verify->entry(1);
         }
	}
?>